//
//  MainTabBarController.m
//  KTVShopProduct
//
//  Created by paeanSs on 2017/11/7.
//  Copyright © 2017年 paeanSs. All rights reserved.
//

#import "MainTabBarController.h"
#import "HomeViewController.h"
#import "MyViewController.h"
#import "ShopViewController.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self setupChildControllers];
    [self setupTabBar];
    [self setupNavBasicSection];
}

- (void)setupNavBasicSection{
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    //设置navBar的背景颜色
    [[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,[UIFont systemFontOfSize:18],NSFontAttributeName,nil]];
}


//创建子vc
- (void)setupChildControllers{
    NSArray *childArrM = @[@"HomeViewController",@"ShopViewController",@"MyViewController"];
    NSArray *titleArrM = @[@"首页",@"商城",@"我"];
    

    NSMutableArray *vcArrM = [NSMutableArray array];
    
    
    for (NSInteger index = 0; index < childArrM.count; index ++) {
        Class vc = NSClassFromString(childArrM[index]);
        UIViewController *ctrlVc = [[vc alloc] init];
        UINavigationController *baseVC = [[UINavigationController alloc] initWithRootViewController:ctrlVc];
        ctrlVc.title = titleArrM[index];
        baseVC.view.backgroundColor = [UIColor colorWithRed:(float)20/255.0f green:(float)25/255.0f blue:(float)28/255.0f alpha:1];
        [vcArrM addObject:baseVC];
    }
    
    self.viewControllers = vcArrM;
}
//创建tabBar
- (void)setupTabBar{
    NSArray *imgNorArrM = @[@"icon_home",@"icon_gouwuche",@"icon_wode"];
    NSArray *imgSelArrM = @[@"icon_home_touch",@"icon_gouwuche_touch",@"icon_wode_touch"];
    NSArray *titleArrM = @[@"首页",@"商城",@"我"];
    for (NSInteger index = 0; index < self.tabBar.items.count; index ++) {
        UITabBarItem *btnItem = self.tabBar.items[index];
        [btnItem setImage:[UIImage imageNamed:imgNorArrM[index]]];
        [btnItem setSelectedImage:[UIImage imageNamed:imgSelArrM[index]]];
        
        if (index == 1) {
            if (@available(iOS 10.0, *)) {
                btnItem.badgeColor = SelectDefalutColor;
            } else {
                // Fallback on earlier versions
            }
            btnItem.badgeValue = @"10";
        }
        
        btnItem.image = [[UIImage imageNamed:imgNorArrM[index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        btnItem.selectedImage = [[UIImage imageNamed:imgSelArrM[index]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        [btnItem setTitle:titleArrM[index]];
//        if (index == 2) {
//            btnItem.imageInsets = UIEdgeInsetsMake(-10, 0, 10, 0);
//        }
    }
//    NSString *tabbarBackgroundImage = [[NSBundle mainBundle] pathForResource:@"img_home_rotation" ofType:@"png"];
    
//    [[UITabBar appearance] setBackgroundImage:[UIImage imageWithContentsOfFile:tabbarBackgroundImage]];
//
  
    [[UITabBar appearance] setBarTintColor:[UIColor whiteColor]];
    [UITabBar appearance].translucent = NO;
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateNormal];
    
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:SelectDefalutColor, NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f],NSFontAttributeName,nil] forState:UIControlStateSelected];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
